// 设置时间
let setTime = function() {
  let res = getCurrentTime();
  $(".currentTime").text(res.currentTime);
  $(".currentDate").text(res.currentDate);
  $(".currentWeek").text(res.currentWeek);
};
setTime();

// 定时更新时间
let timing = function() {
  setInterval(function() {
    setTime();
  }, 1000);
};
timing();


//省市县选择
$("#cityChooseBox").cityChoose(function(id,name){
  $('.city').text(name);
  let url = getAreaMapUrl(id);
  mapChart(url);
})
$(".site").click(function(e){
  e.stopPropagation();
  $("#cityChooseBox").toggle();
})
document.onclick = function(){
  $("#cityChooseBox").hide();
}

const myChart1 = echarts.init(document.getElementById("serviceTimeChart"));
const myChart2 = echarts.init(document.getElementById("gradeRateChart"));
const myChart3 = echarts.init(document.getElementById("mapLeftChart"));
const myChart8 = echarts.init(document.getElementById("mapRightChart"));
const myChart4 = echarts.init(document.getElementById("useSituationChart"));
const myChart5 = echarts.init(document.getElementById("hourUseChart"));
const myChart6 = echarts.init(document.getElementById("warnChart"));
const myChart7 = echarts.init(document.getElementById("useQingChart"));
// 科学使用时长
let serviceTimeChart = function() {
  myChart1.setOption(myChart_option1());
};
serviceTimeChart();

// 年级占比
let gradeRateChart = function() {
  myChart2.setOption(myChart_option2());
};
gradeRateChart();

//各行政区使用分布情况
let mapChart = function(url) {
  $.get(`../${url}`,function(geoJson){
    echarts.registerMap('shanghai', geoJson);
    myChart3.setOption(myChart_option3());
  })
};
mapChart(url='china/china.json');

let mapChart2 = function(){
  myChart8.setOption(myChart_option8());
}
mapChart2();

//近30天装备使用情况
let useSituationChart = function() {
  myChart4.setOption(myChart_option4());
};
useSituationChart();

//近一小时班班通各时段使用情况
let hourUseChart = function() {
  myChart5.setOption(myChart_option5());
};
hourUseChart();

//告警程度以及类别分布
let warnChart = function() { 
  myChart6.setOption(myChart_option6());
};
warnChart();

//使用情况
let useQingChart = function(){
  myChart7.setOption(myChart_option7());
}
useQingChart();


//图例适应屏幕变化
let chartResize = function(){
  myChart1.resize();
  myChart2.resize();
  myChart3.resize();
  myChart4.resize();
  myChart5.resize();
  myChart6.resize();
  myChart7.resize();
  myChart8.resize();
}
window.onresize = debounce(chartResize,500);
